package cn.cjlmonster.demo02.api;

/**
 * This project is Demo02
 * Created by cjl on 2021/11/23 10:56 下午.
 */

import com.google.gson.annotations.SerializedName;

import java.util.List;

import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.Headers;
import retrofit2.http.POST;

/**
 * This project is control-screen
 *
 * @author cjl
 * @date 2021/11/18 10:37
 */
public interface PhnixService {

    @Headers({"Content-Type: application/json;charset=utf-8"})
    @POST("snapshot/proxy.do")
    Call<BaseResult<List<SnapshotBean>>> getSnapshot(@Body SnapshotBody snapshotBody);

    enum Unit {
        day(15), week(15), month(8);

        public int range;

        Unit(int range) {
            this.range = range;
        }
    }

    class SnapshotBody {

        public SnapshotBody(String productId, String rouleId, int deviceId, Unit unit, String... index) {
            this.productId = productId;
            this.rouleId = rouleId;
            this.deviceId = deviceId + "";
            this.unit = unit.name();
            this.range = unit.range;
            this.indexs = index;
        }

        public String productId;
        public String deviceId;
        public String[] indexs;
        public String rouleId;
        public String unit; // day, week, month
        public int range; // 15, 15, 8
        public String mark1 = "maxDiffer";
        public String mark2 = "0";
        public boolean mark3 = false;
        public boolean desc = true;
    }

    /**
     * 五孔插座："30"
     * 电量检测仪："4","20","36","52","68","84"
     */
    class SnapshotBean {
        @SerializedName("snapshot_date")
        public String snapshotDate;

        @SerializedName("30")
        public float value30;

        @SerializedName("4")
        public float value4;

        @SerializedName("20")
        public float value20;

        @SerializedName("36")
        public float value36;

        @SerializedName("52")
        public float value52;

        @SerializedName("68")
        public float value68;

        @SerializedName("84")
        public float value84;

        public float get(int index) {
            switch (index) {
                case 0:
                    return value4;
                case 1:
                    return value20;
                case 2:
                    return value36;
                case 3:
                    return value52;
                case 4:
                    return value68;
                case 5:
                    return value84;
                default:
                    return value30;
            }
        }

        @Override
        public String toString() {
            return "SnapshotBean{" +
                    "snapshotDate='" + snapshotDate + '\'' +
                    ", value30=" + value30 +
                    ", value4=" + value4 +
                    ", value20=" + value20 +
                    ", value36=" + value36 +
                    ", value52=" + value52 +
                    ", value68=" + value68 +
                    ", value84=" + value84 +
                    '}';
        }
    }
}